package com.huaxia.day16;

import java.io.*;

public class ByteIOTest {

    public static void main(String[] args) throws Exception {
        rwBytes();
        rwchar();


    }

    public static void rwBytes() throws IOException {
        File in = new File("D:/11.jpg");
        FileInputStream fis = new FileInputStream(in);
        File out = new File("D:/123_stream.jpg");
        FileOutputStream fos = new FileOutputStream(out);
        ;
        byte[] buf = new byte[1024];
        int len = 0;
        while ((len = fis.read(buf)) != -1) { //读取到buf数组中
            fos.write(buf, 0, len);
        }
        fis.close();
        fos.close();
    }


    public static void rwchar() throws IOException {
        File filer = new File("D:/11.jpg");
        FileReader fr = new FileReader(filer);
        BufferedReader bufr = new BufferedReader(fr);

        File filew = new File("D:/123_reader.jpg");
        FileWriter fw = new FileWriter(filew);
        BufferedWriter bufw = new BufferedWriter(fw);
        String line = null;
        int len = 0;
        char[] buf = new char[1024];
        while ((len = bufr.read(buf)) != -1) { // 读取到buf数组中
            bufw.write(buf, 0, len);
        }
        bufw.flush();
        fr.close();
        bufr.close();
        fw.close();
        bufw.close();

    }

}
